<!-- 污水处理设施 -->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form-model layout="inline">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="设施类型">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.facilityType"
                dictCode="sewage_ps_point_type"
                placeholder="请选择设施类型"
              />
            </a-form-model-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="关联管点编号">
              <a-input v-model="queryParam.pipPointNo"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="所属区域">
              <j-select-depart placeholder="请选择区域id" v-model="areaId" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" style="margin: 0 auto 10px">
                查询
              </a-button>
              <a-button style="margin-left: 10px;" @click="searchReset">
                重置
              </a-button>
            </span>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd('新增污水处理设施')" type="primary" icon="plus">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('管点表')">导出</a-button> -->
      <!-- <a-upload
        name="file"
        :showUploadList="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- <a-upload
        name="file"
        :showUploadList="false"
        :headers="tokenHeader"
        :action="importProgressExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入工程进度</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="superFieldList"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="sewagePointType" slot-scope="text">
          <div>{{ text | filterSewagePointType(sewagePointTypeList) }}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <FacilityModal ref="modalForm" @ok="modalFormOk"></FacilityModal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import FacilityModal from '@views/modules/SewageTreatmentFacilities/modal'
import { getAction } from '@/api/manage'

import { getDictItemListByCode } from '@/api/system.js'

export default {
  name: 'SewageTreatemntFacilities',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    FacilityModal
  },
  filters: {
    filterSewagePointType(val, list) {
      const item = list.find(item => item.value === '' + val)
      if (item) {
        return item.label
      } else {
        return val || '--'
      }
    }
  },
  data() {
    return {
      areaId: '',
      description: '污水处理设施页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (t, r, index) => {
            const { pageSize, current } = this.ipagination
            return (current - 1) * pageSize + parseInt(index) + 1
          }
        },
        {
          title: '设施类型',
          align: 'center',
          dataIndex: 'facilityType',
          scopedSlots: { customRender: 'sewagePointType' }
        },
        {
          title: '污水处理厂名称',
          align: 'center',
          dataIndex: 'facilityName'
        },
        {
          title: '设施Id',
          align: 'center',
          dataIndex: 'id'
        },
        {
          title: '关联管点编号',
          align: 'center',
          dataIndex: 'pipPointNo'
        },
        {
          title: '管点状态',
          align: 'center',
          dataIndex: 'status',
          customRender: (text, record, index) => (text ? (text == 1 ? '规划' : '现状') : '')
        },
        {
          title: '区域',
          align: 'center',
          dataIndex: 'sysOrgCode'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/paishui/paishuiFacility/list',
        delete: '/paishui/paishuiFacility/delete',
        deleteBatch: '/paishui/paishuiFacility/deleteBatch',
        exportXlsUrl: '/paishui/pipPoint/exportXls',
        importExcelUrl: 'paishui/import/excel/easyIpt',
        importProgressExcelUrl: 'paishui/geophysical/excel/easyIpt'
      },
      dictOptions: {},
      superFieldList: [],
      title: '编辑',
      visible: false,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      inquire: {
        areaId: '',
        pipType: '',
        pipNo: '',
        pipPointDefective: undefined
      },
      sewagePointTypeList: [],
      disableMixinCreated: true
    }
  },
  created() {
    this.getSuperFieldList()
    this.handleGetDictItemList('sewage_ps_point_type')
    this.loadData()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    importProgressExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importProgressExcelUrl}`
    }
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.loading = true
      let requireUrl = this.url.list + '/' + (this.areaId ? this.areaId : '0')
      getAction(requireUrl, params)
        .then(res => {
          if (res.success) {
            this.dataInitialize = res.result.records || res.result
            this.superFieldList = res.result.records || res.result
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            this.ipagination.total = res.result.total
            for (let index = 0; index <= res.result.records.length; index++) {
              if (res.result.records[index] && res.result.records[index].deleted === 1) {
                this.dataInitialize.splice(index - 1, 1)
              }
            }
            if (res.result.total) {
              this.ipagination.total = res.result.total
              console.log(this.ipagination.total)
            } else {
              console.log(this.ipagination.total)
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    async handleGetDictItemList(dictCode) {
      const res = await getDictItemListByCode({ dictCode })
      this.sewagePointTypeList = (res.result || []).map(x => {
        return {
          name: x.itemText,
          label: x.itemText,
          value: x.itemValue
        }
      })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'pipName', text: '设施类型', dictCode: 'sewage_ps_point_type' })
      fieldList.push({ type: 'string', value: 'pipNo', text: '污水处理厂名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'pipPointDefective', text: '关联管点编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'pipType', text: '管点状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'associationPosPointNo', text: '区域', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row-flex >>> .ant-col-6 {
  width: 10%;
}
.ant-row >>> .ant-col-4 {
  width: 36.666667%;
}
.search {
  margin-bottom: 25px;
}
.form_add >>> .ant-form-item {
  display: flex;
}
.form_temperatureData >>> .ant-form-item-control-wrapper,
.form_areaId >>> .ant-form-item-control-wrapper {
  width: 186px;
}
</style>
